package com.rem.designPattern.mediator中介者;

/**
 * 用户类
 * 抽象同事类
 *
 * @author Rem
 * @date 2022-11-25
 */
public abstract class Person {

    protected String name;
    protected Mediator mediator;

    public Person(String name, Mediator mediator) {
        this.name = name;
        this.mediator = mediator;
    }

    /**
     * 与中介联系
     *
     * @param message
     */
    abstract void constact(String message);

    /**
     * 获取中介消息
     *
     * @param message
     */
    abstract void getMessage(String message);
}

/**
 * 房东
 * 具体同事类
 */
class HouseOwner extends Person {

    public HouseOwner(String name, Mediator mediator) {
        super(name, mediator);
    }

    /**
     * 与中介者联系
     *
     * @param message
     */
    @Override
    public void constact(String message) {
        mediator.constact(message, this);
    }

    @Override
    public void getMessage(String message) {
        System.out.println("房主" + name + "获取到的信息：" + message);
    }
}

/**
 * 承租人
 * 具体同事类
 */
class Tenant extends Person {
    public Tenant(String name, Mediator mediator) {
        super(name, mediator);
    }

    @Override
    public void constact(String message) {
        mediator.constact(message, this);
    }

    @Override
    public void getMessage(String message) {
        System.out.println("租房者" + name + "获取到的信息：" + message);
    }
}